
#include <gtkmm.h>

#include "regsz_editor.h"

Regsz_Editor::Regsz_Editor(const Glib::ustring & val_name, 
const Glib::ustring & val_data) : origin_data_(val_data)
{
	set_size_request(350, 200);
	set_title("修改字符串");
	//printf("origin string %s\n", origin_data_.c_str());

	Gtk::VBox* area = Gtk::Dialog::get_vbox();
	if (NULL != area) {
		area->set_spacing(10);
		Gtk::VBox *box = Gtk::manage(new Gtk::VBox());		
		area->pack_end(*box);
		box->pack_start(*Gtk::manage(new Gtk::Label(" 数值名称：", Gtk::ALIGN_LEFT)), Gtk::PACK_EXPAND_PADDING);
		Gtk::Entry * name = Gtk::manage(new Gtk::Entry());
		if (NULL != name) {
			name->set_text(val_name);			
			name->property_editable() = false;
			box->pack_start(*name, Gtk::PACK_EXPAND_PADDING);
		}
		
		box->pack_start(*Gtk::manage(new Gtk::Label(" 数值数据：", Gtk::ALIGN_LEFT, Gtk::ALIGN_BOTTOM)), 
		Gtk::PACK_EXPAND_PADDING);
		edit_data_ = Gtk::manage(new Gtk::Entry());
		if (NULL != edit_data_) {
			edit_data_->set_text(origin_data_);			
			box->pack_start(*edit_data_, Gtk::PACK_EXPAND_PADDING);
		}
		show_all_children();
		set_focus(*edit_data_);
	}
	Gtk::Button * ok_btn = add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
	add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
	if (NULL != ok_btn) ok_btn->set_flags(Gtk::CAN_DEFAULT);
}

Regsz_Editor::~Regsz_Editor()
{
}

Glib::ustring
Regsz_Editor::get_result() const
{
	return NULL != edit_data_ ? edit_data_->get_text() : Glib::ustring("");
}

bool
Regsz_Editor::is_modify() const
{
	//printf("new string %s\n", edit_data_->get_text().c_str());
	return (edit_data_->property_text() != origin_data_) ? true : false;
}

Regmultisz_Editor::
Regmultisz_Editor(const Glib::ustring & val_name, Ustrings & val_data) :
origin_data_(val_data)
{
	set_size_request(350, 300);
	set_border_width(4);
	set_title("修改多节字符串");
	Gtk::VBox* area = Gtk::Dialog::get_vbox();
	if (NULL != area) {
		area->set_spacing(10);
		Gtk::VBox *box = Gtk::manage(new Gtk::VBox());		
		area->pack_end(*box);
		box->pack_start(*Gtk::manage(new Gtk::Label(" 数值名称：", Gtk::ALIGN_LEFT)), Gtk::PACK_EXPAND_PADDING);
		Gtk::Entry * name = Gtk::manage(new Gtk::Entry());
		if (NULL != name) {
			name->set_text(val_name);			
			name->property_editable() = false;
			box->pack_start(*name, Gtk::PACK_EXPAND_PADDING);
		}
		
		box->pack_start(*Gtk::manage(new Gtk::Label(" 数值数据：", Gtk::ALIGN_LEFT, Gtk::ALIGN_BOTTOM)), 
		Gtk::PACK_EXPAND_PADDING);
		Gtk::ScrolledWindow * sw = Gtk::manage(new Gtk::ScrolledWindow());
		if (NULL != sw) box->pack_start(*sw, Gtk::PACK_EXPAND_PADDING);
		edit_data_ = Gtk::manage(new Gtk::TextView());
		if (NULL != edit_data_) {
			//edit_data_->set_text(origin_data_);			
			sw->add(*edit_data_);
			sw->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
		}
		show_all_children();
		set_focus(*edit_data_);
	}
	Gtk::Button * ok_btn = add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
	add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
	if (NULL != ok_btn) ok_btn->set_flags(Gtk::CAN_DEFAULT);
}

Regmultisz_Editor::~Regmultisz_Editor()
{
}

Ustrings Regmultisz_Editor::get_result() const
{
	Ustrings result;
	return result;
}

bool	Regmultisz_Editor::is_modified() const
{
	return false;
}
